home *** CD-ROM | disk | FTP | other *** search
/ Delphi Developer's Kit 1996 / Delphi Developer's Kit 1996.iso / power / regmax.000 / regmax.bas < prev    next >
BASIC Source File  |  1995-12-22  |  17KB  |  508 lines

  1. '   ******************************************************
  2. '   //THIS MODULE (REGMAX.BAS) IS DESIGNED TO BE INCLUDED IN YOUR
  3. '   //OWN PROJECT, AND CONTAINS ALL THE GBLIB2 FUNCTIONS
  4. '   //NECESSARY TO WRITE AND READ REGISTRATION DATA.
  5. '   //IT MUST BE USED IN CONJUNCTION WITH GBLIB2.EXE.
  6. '   //REGMAX.EXE, REGMAX.BAS (c)1995 Gordon Bamber//
  7. '   ******************************************************
  8.  
  9. Option Explicit
  10. '   /* Modified 11/01/95 [GB] */
  11. '   /* Modified 06/01/95 [GB] */
  12. '   /* Modified 02/01/95 [GB] */
  13. '   /* Modified 31/12/94 [GB] */
  14. '   /* Created 31/12/94 [GB] */
  15.  
  16.  
  17. '   //WIN31 API Function to bar accidents in development mode!//
  18. '   //Alised so as not to clash with other declares in this project//
  19. Declare Function FindIt Lib "User" Alias "FindWindow" (ByVal lpClassName As String, ByVal lpWindowName As String) As Integer
  20.  
  21. '   //*************** Declares for the API in GBLIB2.EXE *************//
  22.  
  23. '   //This function is a crude string -> number algorithm//
  24. '   //It can be used to make a checksum of the registration information//
  25. Declare Function MakeAKey Lib "GBLIB2.EXE" (ByVal AString As String) As Long
  26. Declare Sub Encryptit Lib "GBLIB2.EXE" (ByVal AString As String, AStringLen As Integer)
  27.  
  28. '   //The next three functions must NOT be used in development mode//
  29. '   //on this project, because they are designed to//
  30. '   //modify this application's EXE file directly, and until it has been//
  31. '   //compiled, there is no EXE file to modify!
  32. Declare Function WriteRegData Lib "GBLIB2.EXE" (ByVal sz_Name As String, ByVal sz_Org As String, ByVal sz_EXEPath As String, ByVal MyPhrase As String) As Integer
  33. Declare Function ReadRegData Lib "GBLIB2.EXE" (ByVal sz_EXEPath As String, ByVal sz_Name As String, ByVal sz_Org As String, ByVal YMD As String, NameLen As Integer, OrgLen As Integer) As Integer
  34. Declare Function CheckRegistration Lib "GBLIB2.EXE" (ByVal sz_EXEPath As String) As Integer
  35.  
  36. Declare Function WriteRegDataToINI Lib "GBLIB2.EXE" (ByVal sz_Name As String, ByVal sz_Org As String, ByVal sz_EXEPath As String) As Integer
  37. Declare Function ReadRegDataFromINI Lib "GBLIB2.EXE" (ByVal sz_EXEPath As String, ByVal sz_Name As String, ByVal sz_Org As String, NameLen As Integer, OrgLen As Integer) As Integer
  38.  
  39. '   //These Subs simply show information//
  40. Declare Sub ShowWinDir Lib "GBLIB2.EXE" ()
  41. Declare Sub ShowSysDir Lib "GBLIB2.EXE" ()
  42.  
  43. '   //******************************************************************//
  44.  
  45. '   //***** Data constants *****//
  46. Global Const MONTHSTRING = "JanFebMarAprMayJunJulAugSepOctNovDec"
  47.  
  48. '   //############# ALTER THIS IF NEEDED ##############//
  49. Global Const EXPIRYDAYS = 31'   //No. of days to expiry//
  50. '   //############# ALTER THIS IF NEEDED ##############//
  51.  
  52. '   //******************************************************************//
  53.  
  54. '   //***** Global Registration variables *****//
  55. Global sz_EXEPath As String'    //The full path to a VB3 Executable//
  56.  
  57. Global EXPIRED As Integer'  //True/False. Set in GetDataFromEXE//
  58. '                           //depends on constant EXPIRYDAYS//
  59.  
  60. Global USERNAME As String'  //33 characters maximum//
  61. Global USERORG As String'   //33 characters maximum//
  62. Global BRANDDATE As String' //4 Characters//
  63.  
  64. Global BRANDYEAR As Integer'    //Range 95->//
  65. Global BRANDMONTH As Integer'   //Range 1-12//
  66. Global BRANDDAY As Integer'     //Range 1-31//
  67.  
  68. '   //LONG Values depend on whether MSFINX.DLL is available//
  69. Global LONGBRANDDATE As Long'   //Date registered/branded//
  70. Global LONGTODAYSDATE As Long'  //System date//
  71.  
  72. Global INI_USERNAME As String'  //33 characters maximum//
  73. Global INI_USERORG As String'   //33 characters maximum//
  74.  
  75. '   //******************************************************************//
  76.  
  77. Function Check_ErrorString (i_Errorcode As Integer) As String
  78.  
  79. '   /* Modified 15/01/95 [GB] */
  80. '   /* Created 15/01/95 [GB] */
  81. Dim msg As String
  82. Select Case i_Errorcode
  83. Case 0
  84.     msg = "OK"
  85. Case 1
  86.     msg = "Name= entry does not match registration details"
  87. Case 2
  88.     msg = "Organisation= entry does not match registration details"
  89. Case 3
  90.     msg = "Both registration entries in the INI file have been altered"
  91.  
  92. '   // Value > 8192 means that the EXE-file is unbranded/corrupt//
  93. Case 8303
  94.     msg = "Registration details in EXE file are absent. INI file is present."
  95.  
  96. '   //Value > 16384 means that the INI-File is corrupt/absent//
  97. Case 16389
  98.     msg = "EXE is Unbranded. Name entry Name= is blank. Organisation= entry is correct."
  99. Case 16402
  100.     msg = "EXE is Unbranded. Name entry Name= is correct. Organisation= entry is blank."
  101. Case 16403
  102.     msg = "EXE is Unbranded. INI entry Name= is blank. Organisation= entry is incorrect."
  103. Case 16415
  104.     msg = "EXE is Unbranded. INI entry Organisation= is blank. Name= entry is incorrect."
  105. Case 16416
  106.     msg = "EXE is Unbranded. INI entry Name= is absent. Organisation= entry is incorrect."
  107. Case 16419
  108.     msg = "EXE is Unbranded. INI entry Name= is blank. Organisation= entry is blank."
  109. Case 16426
  110.     msg = "EXE is Unbranded. INI entry Name= is correct. Organisation= entry is missing."
  111. Case 16437
  112.     msg = "EXE is Unbranded. INI entry Name= is incorrect. Organisation= entry is missing."
  113. Case 16445
  114.     msg = "EXE is Unbranded. INI file is missing."
  115. Case 16454
  116.     msg = "This is a totally unregistered file."
  117. Case Else
  118.     msg = "Unknown error. (Code #" & Format$(i_Errorcode) & ")"
  119. End Select
  120. Check_ErrorString = msg
  121.  
  122. End Function
  123.  
  124. Sub DevMsg ()
  125.  
  126. '   /* Modified 11/01/95 [GB] */
  127. '   /* Modified 31/12/94 [GB] */
  128. '   /* Created 31/12/94 [GB] */
  129.  
  130. '   //This message is shown if ISVBRUNNING returns true//
  131.  
  132. Dim msg As String
  133. msg = "You are working in Development Mode" & Chr$(10) & Chr$(10)
  134. msg = msg & "I cannot therefore read or write data" & Chr$(10)
  135. msg = msg & "to or from this application," & Chr$(10)
  136. msg = msg & "because you havn't compiled it yet!" & Chr$(10)
  137. msg = msg & "Compile this application, and run it" & Chr$(10)
  138. msg = msg & "outside of the Visual Basic IDE entirely."
  139. MsgBox msg, 48, "REGMAX - Get / PutDataIntoEXE"
  140. End Sub
  141.  
  142. Sub DisplayRegInfo ()
  143. '   /* Modified 14/01/95 [GB] */
  144. '   /* Modified 06/01/95 [GB] */
  145. '   /* Created 06/01/95 [GB] */
  146.  
  147. Dim i_EXERetVal As Integer
  148. Dim i_INIRetVal As Integer
  149. i_EXERetVal = GetDataFromEXE()' //Sets USERNAME and USERORG//
  150. i_INIRetVal = GetDataFromINI()' //Sets INI_USERNAME and INI_USERORG//
  151. Dim msg As String
  152. msg = ""
  153.  
  154.  
  155. If (i_INIRetVal + i_EXERetVal) > 0 Then
  156.     msg = msg & "This software is Unregistered."
  157. Else
  158.     '   //Display embedded registration information//
  159.     msg = msg & "This software is registered" & Chr$(10)
  160.     msg = msg & "to: " & USERNAME & Chr$(10)
  161.     msg = msg & "of: " & USERORG
  162. End If
  163. MsgBox msg, 64 + 4096, "Registration Information"
  164.  
  165. End Sub
  166.  
  167. Function DisplayRegInfoFromINI () As Integer
  168.  
  169. '   /* Modified 14/01/95 [GB] */
  170. '   /* Created 14/01/95 [GB] */
  171.  
  172. Dim i_RetVal As Integer
  173. i_RetVal = GetDataFromINI()
  174. DisplayRegInfoFromINI = i_RetVal
  175. Dim msg As String
  176.  
  177. If i_RetVal > 0 Then
  178.     msg = "This is an Unregistered INI."
  179. Else
  180.     '   //Display embedded registration information//
  181.     msg = "This software is registered" & Chr$(10)
  182.     msg = msg & "to: " & INI_USERNAME & Chr$(10)
  183.     msg = msg & "of: " & INI_USERORG
  184. End If
  185. MsgBox msg, 64 + 4096, "INI Registration Information"
  186.  
  187. End Function
  188.  
  189. Sub DisplayRegInfoWithExpiry ()
  190. '   /* Modified 14/01/95 [GB] */
  191. '   /* Modified 06/01/95 [GB] */
  192. '   /* Created 06/01/95 [GB] */
  193.  
  194. Dim i_RetVal As Integer
  195. i_RetVal = GetDataFromEXE()
  196.  
  197. Dim msg As String
  198. If i_RetVal > 0 Then
  199.     msg = "This software is Unregistered."
  200. Else
  201.     '   //Display embedded registration information//
  202.     msg = "This software was registered" & Chr$(10)
  203.     msg = msg & "to: " & USERNAME & Chr$(10)
  204.     msg = msg & "of: " & USERORG
  205.  
  206.     '   //Optional line//
  207.     msg = msg & Chr$(10) & "on: " & BRANDDATE
  208.  
  209.     '   //EXPIRED is set True/False by GetDataFromEXE//
  210.     '   //EXPIRYDAYS is a Global Const set in (declarations) //
  211.     If EXPIRED <> False Then
  212.     msg = msg & Chr$(10) & Chr$(10) & "* YOUR " & Format$(EXPIRYDAYS) & "-DAY EVALUATION" & Chr$(10)
  213.     msg = msg & "PERIOD HAS NOW EXPIRED."
  214.     '   //Kill Application from the Hard Disk here//
  215.     End If' //of If EXPIRED//
  216. End If' //of If UNLICENSED//
  217.  
  218. MsgBox msg, 64 + 4096, "Registration Information"
  219.  
  220. End Sub
  221.  
  222. Function Get_sz_CurrentEXEPath () As String
  223.  
  224. '   /* Modified 14/01/95 [GB] */
  225. '   /* Created 14/01/95 [GB] */
  226.  
  227. Dim sz_TempPath As String
  228.  
  229. '   //Get the full path and filename of this application//
  230. sz_TempPath = App.Path
  231. If Right$(sz_TempPath, 1) <> "\" Then sz_TempPath = sz_TempPath & "\"
  232. sz_TempPath = sz_TempPath & App.EXEName & ".EXE"
  233.  
  234. Get_sz_CurrentEXEPath = sz_TempPath
  235. End Function
  236.  
  237. Function GetDataFromEXE () As Integer
  238.  
  239. On Error GoTo ERR_GDFE
  240. '   /* Modified 14/01/95 [GB] */
  241. '   /* Modified 11/01/95 [GB] */
  242. '   /* Modified 06/01/95 [GB] */
  243. '   /* Modified 02/01/95 [GB] */
  244. '   /* Modified 30/12/94 [GB] */
  245. '   /* Created 30/12/94 [GB] */
  246.  
  247. '   //Quit out in development mode//
  248. If ISVBRUNNING() <> 0 Then
  249.     DevMsg
  250.     Exit Function
  251. End If
  252.  
  253. Dim i_RetValue As Integer
  254. Dim NameLen As Integer
  255. Dim OrgLen As Integer
  256. Dim TUserName As String
  257. Dim TUserOrg As String
  258. Dim YMD As String
  259.  
  260. '   //Initialise//
  261. EXPIRED = False
  262. BRANDDATE = "UNKNOWN"
  263. LONGBRANDDATE = 0
  264. LONGTODAYSDATE = 0
  265.  
  266. '******** REM out next section if reading an external program **********
  267.  
  268. '***********************************************************************
  269.  
  270. '   //You MUST initialise the strings to this length or VB cannot//
  271. '   //cope with passing strings to/from the GBLIB2 API//
  272. TUserName = String$(42, 0)
  273. TUserOrg = String$(34, 0)
  274. YMD = String$(4, 0)
  275.  
  276. '   //Read the Information from the EXE//
  277. i_RetValue = ReadRegData(sz_EXEPath, TUserName, TUserOrg, YMD, NameLen, OrgLen)
  278. '   //Return value is Zero if sz_EXEPath is branded OK, otherwise 1//
  279. '   //TUserName(NameLen+1) is ASCII(0)
  280. '   //TUserOrg(OrgLen+1) is ASCII(0)
  281.  
  282. '   //If the EXE is 'virgin' then i_RetVal=1
  283. '     and USERNAME and USERORG = 'UNLICENSED' //
  284.  
  285. '   //Trim to the last useable character//
  286. USERNAME = Left$(TUserName, NameLen)
  287. USERORG = Left$(TUserOrg, OrgLen)
  288.  
  289. GetDataFromEXE = i_RetValue
  290. '   //Now process the DATE information//
  291. '   //If the EXE is virgin then YMD is all spaces or ASCII 0//
  292. If Left$(YMD, 1) = " " Then Exit Function
  293. If Left$(YMD, 1) = Chr$(0) Then Exit Function
  294.  
  295. '   //YMD = The Year-Month-Date in ASCII codes//
  296. '   //Here I unpack the YMD data into the 'English' form of dd mmmm yyyy//
  297.  
  298. '   //1) Day//
  299. BRANDDAY = Asc(Mid$(YMD, 3, 1))
  300. BRANDDATE = Format$(BRANDDAY, "#0")
  301.  
  302. '   //2) Month//
  303. BRANDMONTH = Asc(Mid$(YMD, 2, 1))
  304. BRANDDATE = BRANDDATE & " " & Mid$(MONTHSTRING, (BRANDMONTH) * 3 - 2, 3)
  305.  
  306. '   //3) Year//
  307. '   //NOTE it is returned as (YY+108)//
  308. BRANDYEAR = Asc(Left$(YMD, 1)) - 108
  309. BRANDDATE = BRANDDATE & " 19" & Format$(BRANDYEAR, "00")
  310.  
  311. On Error GoTo NO_MSFINX_DLL
  312. '   //Make up numbers (that vary in days) for expiry comparisons//
  313. '   //Use financial functions if available//
  314. '   //Remember to include the financial DLLs on your distribution disk(s)//
  315. LONGBRANDDATE = DateSerial(BRANDYEAR, BRANDMONTH, BRANDDAY)
  316. LONGTODAYSDATE = DateSerial(Year(Now), Month(Now), Day(Now))
  317. If Abs(LONGTODAYSDATE - LONGBRANDDATE) > EXPIRYDAYS Then EXPIRED = True
  318. '   //All OK//
  319. Exit Function
  320.  
  321.  
  322. '   //DateSerial function has caused an error, so come here//
  323. GDFE_OUT:
  324. '   //Resume here if VB3 Financial DLLs (e.g. MSFINX.DLL) are absent//
  325. LONGBRANDDATE = Val(Format$(BRANDYEAR, "00") & Format$(BRANDMONTH, "00") & Format$(BRANDDAY, "00"))
  326. LONGTODAYSDATE = Val(Format$(Now, "yymmdd"))
  327. '   //This will not work so well across month boundaries...//
  328. If Abs(LONGTODAYSDATE - LONGBRANDDATE) > EXPIRYDAYS Then EXPIRED = True
  329.  
  330. '   //Resume here from a fatal error//
  331. GDFE_ERROR:
  332. Exit Function
  333.  
  334.  
  335. NO_MSFINX_DLL:
  336. '   //Triggered ErrorHandler//
  337. '   //Come here if VB3 Financial DLL is absent, and triggers an error//
  338. Resume GDFE_OUT
  339.  
  340. ERR_GDFE:
  341. '   //Fatal ErrorHandler//
  342. MsgBox "Unable to fetch registration data", 48, "Sub GetDataFromEXE"
  343. Resume GDFE_ERROR
  344. End Function
  345.  
  346. Function GetDataFromINI () As Integer
  347.  
  348.  
  349. '   /* Modified 14/01/95 [GB] */
  350. '   /* Created 14/01/95 [GB] */
  351.  
  352. Dim TUserName As String
  353. Dim TUserOrg As String
  354. Dim i_RetValue As Integer
  355. Dim NameLen As Integer
  356. Dim OrgLen As Integer
  357.  
  358.  
  359. '   //You MUST initialise the strings to this length or VB cannot//
  360. '   //cope with passing strings to/from the GBLIB2 API//
  361. TUserName = String$(42, 0)
  362. TUserOrg = String$(34, 0)
  363.  
  364. '   //Read the Information from the INI//
  365. i_RetValue = ReadRegDataFromINI(sz_EXEPath, TUserName, TUserOrg, NameLen, OrgLen)
  366. GetDataFromINI = i_RetValue
  367. '   //Return value is Zero if sz_EXEPath is branded OK, otherwise 1 or more//
  368. '   //i_RetVal=10 - Not a VB V3.0 program//
  369. '   //i_RetVal=11 - A VB V2.0 program//
  370. '   //i_RetVal=12 - A TPW program//
  371. '   //i_RetVal=13 - A 32-Bit program//
  372.  
  373.  
  374. '   //TUserName(NameLen+1) is ASCII(0)
  375. '   //TUserOrg(OrgLen+1) is ASCII(0)
  376.  
  377. '   //If the INI is absent then i_RetVal=1
  378. '     and USERNAME and USERORG = 'UNLICENSED' //
  379.  
  380. '   //Trim to the last useable character//
  381. INI_USERNAME = Left$(TUserName, NameLen)
  382. INI_USERORG = Left$(TUserOrg, OrgLen)
  383.  
  384. End Function
  385.  
  386. Function IsUnRegistered () As Integer
  387.  
  388.  
  389. '   /* Modified 14/01/95 [GB] */
  390. '   /* Created 14/01/95 [GB] */
  391.  
  392. Dim i_RetVal As Integer
  393.  
  394.  
  395. i_RetVal = GetDataFromEXE()
  396. i_RetVal = GetDataFromINI()
  397. i_RetVal = CheckRegistration(sz_EXEPath)
  398. IsUnRegistered = i_RetVal
  399.  
  400.  
  401. End Function
  402.  
  403. Function ISVBRUNNING () As Integer
  404. '   /* Modified 06/01/95 [GB] */
  405.  
  406. '   /* Modified 31/12/94 [GB] */
  407. '   /* Created 31/12/94 [GB] */
  408.  
  409. '   //Debugging line - Ignore//
  410. If LCase(Command$) = "debug" Then
  411.     ISVBRUNNING = 0
  412.     Exit Function
  413. End If
  414.  
  415. '   //Simple test to see if VB is in development mode//
  416. If FindIt("wndclass_desked_gsk", "Microsoft Visual Basic [run]") > 0 Then
  417.     ISVBRUNNING = 1
  418. Else
  419.     ISVBRUNNING = 0
  420. End If
  421. End Function
  422.  
  423. Function PutDataIntoEXE (AName As String, AnOrganisation As String, sz_Key As String) As Integer
  424. '   /* Modified 14/01/95 [GB] */
  425. '   /* Modified 06/01/95 [GB] */
  426.  
  427. '   /* Modified 31/12/94 [GB] */
  428. '   /* Created 31/12/94 [GB] */
  429.  
  430. '   //OPTIONAL//
  431. '   //Quit if running in development mode//
  432.  If ISVBRUNNING() <> 0 Then
  433.      DevMsg
  434.      Exit Function
  435.  End If
  436.  
  437. Dim i_RetValue As Integer
  438.  
  439. '   //OPTIONAL//
  440.  
  441. '   //NOTE: sz_EXEPath could be set to any VB3 program, not//
  442. '   //just this one.
  443.  
  444. '   //Do the deed. Note that AName and AnOrganisation will be truncated//
  445. '   //if either are over 33 characters//
  446.  
  447. i_RetValue = WriteRegData(AName, AnOrganisation, sz_EXEPath, sz_Key)
  448. PutDataIntoEXE = i_RetValue
  449.  
  450. '   //Return value is zero for success/
  451. '   //Return value is 1 if either item has been truncated//
  452. '   //Return value is 2 if USERNAME was an empty string//
  453. '   //Return value is 3 if USERORG was an empty string//
  454. '   //Return value is 99 if sz_Key was bad//
  455.  
  456.  
  457. End Function
  458.  
  459. Function PutDataIntoINI (AName As String, AnOrganisation As String) As Integer
  460.  
  461. '   /* Modified 14/01/95 [GB] */
  462. '   /* Created 14/01/95 [GB] */
  463.  
  464. '   //OPTIONAL//
  465. '   //Quit if running in development mode//
  466. If ISVBRUNNING() <> 0 Then
  467.     DevMsg
  468.     Exit Function
  469. End If
  470.  
  471. Dim i_RetValue As Integer
  472.  
  473. '   //NOTE: sz_EXEPath could be set to any VB3 program, not//
  474. '   //just this one.
  475.  
  476. '   //Do the deed. Note that AName and AnOrganisation will be truncated//
  477. '   //if either are over 33 characters//
  478.  
  479. '   //Write to/Create and write to (APP.EXEName).INI file in WINDOWS directory//
  480. i_RetValue = WriteRegDataToINI(AName, AnOrganisation, sz_EXEPath)
  481. '   //Return value is zero for success/
  482. '   //Return value is 1 if USERNAME was an empty string//
  483. '   //Return value is 2 if USERORG was an empty string//
  484. '   //Return value is 3 if unable to write User= entry in the INIFile//
  485. '   //Return value is 4 if unable to write Organisation= entry in the INIFile//
  486. '   //Return value is 99 if sz_Key was bad//
  487. PutDataIntoINI = i_RetValue
  488. End Function
  489.  
  490. Sub ShowSplash ()
  491.  
  492. '   /* Modified 14/01/95 [GB] */
  493. '   /* Modified 06/01/95 [GB] */
  494. '   /* Created 06/01/95 [GB] */
  495. Dim i_RetVal As Integer
  496.  
  497. i_RetVal = GetDataFromEXE()
  498.  
  499. '   //Is it a 'virgin' EXE? //
  500. If USERNAME = "UNLICENSED" Then
  501.     MsgBox "This is an unlicensed copy of " & App.EXEName, 64 + 4096, App.EXEName & " Registration Information"
  502. Else
  503. '   //Display embedded registration information//
  504.     DisplayRegInfo
  505. End If
  506. End Sub
  507.  
  508.